package com.itheima.reflect;

import com.itheima.domain.Student;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

/*
各种获取方法对象
 */
public class Demo04 {

    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {

        Class<Student> clazz = Student.class;
        //获取 非私有的方法  包含 父类继承的方法
        Method[] methods = clazz.getMethods();
        System.out.println(Arrays.toString(methods));

        //获取所有的方法 包含私有  但是不包含 父类的方法
        Method[] declaredMethods = clazz.getDeclaredMethods();
        System.out.println(Arrays.toString(declaredMethods));


        Method toString = clazz.getMethod("toString");
        Method equals = clazz.getMethod("equals", Object.class);
        Method dance = clazz.getMethod("dance", String.class);
        Method rap = clazz.getMethod("rap");
      //  Method sing1 = clazz.getMethod("sing");
        Method sing2 = clazz.getDeclaredMethod("sing");
        System.out.println(toString);
        System.out.println(equals);
        System.out.println(dance);
        System.out.println(rap);
        //System.out.println(sing1);
        System.out.println(sing2);
        Student student = clazz.getConstructor().newInstance();
        Student student1 = clazz.getConstructor().newInstance();

        Object result = toString.invoke(student);
        System.out.println(result);
        System.out.println(equals.invoke(student, student1));
        System.out.println(student==student1);
        sing2.setAccessible(true);
        Object invoke = sing2.invoke(student);
        System.out.println(invoke);
        Object invoke1 = dance.invoke(student,"大碗宽面");
        System.out.println(invoke1);

        Object invoke2 = rap.invoke(student);
        System.out.println(invoke2);


    }


}
